package day01;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Jetwang
 * @version 1.0
 * @since 2023/3/11 17:09
 * 从尾到头打印链表
 */
public class Offer06 {
    public int[] reversePrint(ListNode head) {
        if (head == null) {
            return new int[0];
        }
        int count = 0;
        ListNode temp = head;
        while(temp != null) {
            count++;
            temp = temp.next;
        }
        int[] res = new int[count];
        int k = count - 1;
        while(head != null) {
            res[k--] = head.val;
            head = head.next;
        }
        return res;
    }
}
